/*
 * @(#) Home.js
 *
 * <br> Copyright:  Copyright (c) 2017
 * <br>
 * <br> @author caijinhuang
 * <br> 2017-11-16 09:47:59
 */

import React from 'react';
/*自定义组件*/
import Title from './mainList/Title'
import MainBody from './mainList/MainBody'
import {UserUtil} from '../UserUtil'

class Home extends React.Component {


    constructor(){
        super();
        this.state={
            userInfo:{}//用户信息
        }
    }
    /**
     * 渲染前查询权限
     */
    componentWillMount() {
        this.rendderInite();
    }

    /*初始化*/
    rendderInite() {
        let url = "/sharemeeting/login/getMeeting.do";
        /*异步请求*/
        fetch(url,{
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            credentials: 'include',
            body: JSON.stringify({})
        }).then((response) => response.json()) //把response转为json
          .then((responseData) => { // 上面的转好的json
                if(responseData.status === false){
                    window.location.href="#/";
                }else{
                    this.reset(responseData.data);
                }
            }).catch((error)=> {
            window.location.href="#/";
        })
    }

    /**
     * 父组件更新子组件状态
     * @param data
     */
    renderSeachList(title) {
        this.refs.meetingList.resetList(title);
    }

    reset(data) {
        UserUtil.userInfo = data;
        this.setState({userInfo:data});
        console.info("用户User:",UserUtil.userInfo);
        console.log(this.state.userInfo)
    }

    render() {
            return (
                <div>
                    <Title renderList={this.renderSeachList.bind(this)} />
                    <MainBody userInfo={this.state.userInfo} ref="meetingList"/>
                </div>
            );
    }
}
export default Home
